/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.qframe.client.quicklet.beans;

import org.qframe.client.error.TemplateConfigError;
import org.qframe.client.quicklet.QuickletFactory;

/**
 * Quicklet class bean form the <quicklet/> tag.
 * Every instance represents a specic instance on the ui (currently rendered or not rendered).
 *
 * @author gprasad
 */
public class Quicklet {

    private String quickletId;
    private String quickletPath;

    /**
     * Creates a Quicklet object.
     * 
     * @param quickletId
     */
    public Quicklet(String quickletId) {
        this.quickletId = quickletId;
        init();
    }

    /**
     *
     * Returns the Quicklet ID as defined in your <quicklet id='xx'/> tag/
     * Note : This is the template id and not the instance id.
     *
     * @return String
     */
    public String getQuickletId() {
        return quickletId;
    }

    /**
     *
     * Returns the  relative path (from WEB-INF) of the quicklet. As defined in
     * the QHandler
     * 
     * @return String path
     */
    public String getPath() {
        return quickletPath;
    }

    private void init() {

        quickletPath = QuickletFactory.getQuickletPath(quickletId);
        TemplateConfigError.throwIf((quickletPath == null || quickletPath.trim().equals("")),
                "Unable to get quicklet path. Have you defined the QuickletHandler and annotated with QHandler ? for  : " + quickletId);
    }
}
